<template>
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>

          <a-col :xs="24" :sm="12">
            <a-form-item label="资产编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['assetCode', validatorRules.assetCode]" :disabled="disableSubmit"
                       placeholder="请输入资产编码"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="取得方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!--              <span v-if="disableSubmit" >{{model.assetClass}}</span>-->
              <!--              <j-dict-select-tag v-else type="list" v-decorator="['assetClass', validatorRules.assetClass]" :trigger-change="true" dictCode="zcgl_asset_classify" placeholder="请选择资产类别"/>-->
              <j-search-select-tag type="list" v-decorator="['assetClass', validatorRules.assetClass]"
                                   :trigger-change="true" dict="zcgl_asset_classify" :disabled="disableSubmit"
                                   placeholder="请选择取得方式"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="资产类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!--              <j-search-select-tag type="list" v-decorator="['assetType', validatorRules.assetClass]"-->
              <!--                                   :trigger-change="true" dict="gf_zcgl_asset_type" :disabled="disableSubmit"-->
              <!--                                   placeholder="请选择资产类型"/>-->
              <j-select-asset-category v-decorator="['assetType',validatorRules.assetClass]"></j-select-asset-category>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="资产名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['assetName', validatorRules.assetName]" :disabled="disableSubmit"
                       placeholder="请输入资产名称"></a-input>
            </a-form-item>
          </a-col>

<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="所属区域" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <j-tree-select-->
<!--                :disabled="disableSubmit"-->
<!--                v-decorator="['regionId', validatorRules.regionId]"-->
<!--                placeholder="请选择区域"-->
<!--                dict="zcgl_region,region_name,id"-->
<!--                pidField="parent_id"-->
<!--                pidValue=""-->
<!--              />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <!--          condition='{"del_flag":"0"}'-->
          <!--          <a-col :xs="24" :sm="12"  v-show="disableSubmit">-->
          <!--            <a-form-item label="所属区域" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
          <!--              <a-input v-decorator="['regionId_dictText']"-->
          <!--                       :disabled="disableSubmit" placeholder=""></a-input>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->

          <a-col :xs="24" :sm="12">
            <a-form-item label="产权单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['propertyRightUnit', validatorRules.propertyRightUnit]"
                       :disabled="disableSubmit" placeholder="请输入产权单位"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="产权证编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['propertyRightCode', validatorRules.propertyRightCode]"
                       :disabled="disableSubmit" placeholder="请输入产权证编号"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="经营情况" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input v-decorator="['businessCircumstance', validatorRules.businessCircumstance]"-->
<!--                       :disabled="disableSubmit" placeholder="请输入经营情况"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="接收时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date :disabled="disableSubmit" placeholder="请选择接收时间"
                      v-decorator="['receiptTime', validatorRules.receiptTime]" :trigger-change="true"
                      style="width: 100%"/>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="接收类型" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input v-decorator="['receiptType', validatorRules.receiptType]"-->
<!--                       :disabled="disableSubmit" placeholder="请输入接收类型"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="管理单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <!--              <a-input v-decorator="['managementUnitId', validatorRules.managementUnitId]"-->
              <!--                       :disabled="disableSubmit" placeholder="请输入管理单位"></a-input>-->
              <j-company-select-tag :disabled="disableSubmit" placeholder="请选择管理单位" v-decorator="[ 'managementUnitId', validatorRules.managementUnitId]" :trigger-change="true"/>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="权利类型" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <j-search-select-tag type="list" v-decorator="['landAuthorityType', validatorRules.landAuthorityType]"-->
<!--                                   :trigger-change="true" dict="zcgl_land_authority_type" :disabled="disableSubmit"-->
<!--                                   placeholder="请选择权利类型"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="权籍情况" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-search-select-tag type="list" v-decorator="['rightCitizenshipSituation', validatorRules.rightCitizenshipSituation]"
                                   :trigger-change="true" dict="zcgl_right_citizenship_situation" :disabled="disableSubmit"
                                   placeholder="请选择权籍情况"/>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="权属情况" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <j-search-select-tag type="list" v-decorator="['ownershipSituation', validatorRules.ownershipSituation]"-->
<!--                                   :trigger-change="true" dict="zcgl_ownership_situation" :disabled="disableSubmit"-->
<!--                                   placeholder="请选择权属情况"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="使用权人名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['holderRightName', validatorRules.holderRightName]"
                       :disabled="disableSubmit" placeholder="请输入使用权人名称"></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="使用权证号" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input v-decorator="['licenseNumber', validatorRules.licenseNumber]"-->
<!--                       :disabled="disableSubmit" placeholder="请输入使用权证号"></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="收款税率" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['collectionRate', validatorRules.collectionRate]"
                              :disabled="disableSubmit" placeholder="请输入收款税率" style="width: 100%"></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="是否抵押" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-search-select-tag type="list" v-decorator="['izMortgage', validatorRules.izMortgage]"
                                   :trigger-change="true" dict="yn" :disabled="disableSubmit"
                                   placeholder="请选择是否抵押"/>
            </a-form-item>
          </a-col>
          <!--          <a-col :xs="24" :sm="12">-->
          <!--            <a-form-item label="商户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
          <!--              <a-input v-decorator="['merchantName']"-->
          <!--                        :disabled="disableSubmit" placeholder="请输入商户名称"></a-input>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->
          <a-col :xs="24" :sm="12">
            <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-search-select-tag type="list" v-decorator="['status', validatorRules.status]" :trigger-change="true"
                                   dict="zcgl_asset_status" :disabled="disableSubmit" :valueExclude="[1]" @change="statusChange" placeholder="请选择状态"/>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="管理人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-search-select-tag v-decorator="['managerId']" :async="true" :disabled="disableSubmit" dict="sys_user,realname,id"
                                   placeholder="请选择管理人员"/>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="楼层" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['floorNumber', validatorRules.floorNumber]" :disabled="disableSubmit"
                       placeholder="请输入楼层"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="建成年份" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['buildTime', validatorRules.buildTime]" :disabled="disableSubmit"
                       placeholder="请输入建成年份"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="结构" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['houseStructure', validatorRules.houseStructure]" :disabled="disableSubmit"
                       placeholder="请输入结构"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="房屋用途" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['houseUse', validatorRules.houseUse]" :disabled="disableSubmit"
                       placeholder="请输入房屋用途"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="土地用途" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['landUse']" :disabled="disableSubmit" placeholder="请输入土地用途"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="土地权利性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['landAuthorityNature']" :disabled="disableSubmit"
                       placeholder="请输入土地权利性质"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="取得日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date :disabled="disableSubmit" placeholder="请选择取得日期" v-decorator="['getTime']" :trigger-change="true"
                      style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="出让终止日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date :disabled="disableSubmit" placeholder="请选择出让终止日期" v-decorator="['toSellEndtime']"
                      :trigger-change="true"
                      style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="产权面积（m²）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['propertyRightArea', validatorRules.propertyRightArea]"
                              :disabled="disableSubmit" placeholder="请输入产权面积（m²）" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="建筑面积（m²）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['coveredArea', validatorRules.coveredArea]" :disabled="disableSubmit"
                              placeholder="请输入建筑面积（m²）"
                              style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="出租面积（m²）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['landUseArea', validatorRules.landUseArea]" :disabled="disableSubmit"
                              placeholder="请输入出租面积（m²）"
                              style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="土地性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['landStatus']" :trigger-change="true"
                                 dictCode="zcgl_asset_soiltype" :disabled="disableSubmit" placeholder="请选择土地性质"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="房屋性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['roomType']" :trigger-change="true"
                                 dictCode="zcgl_asset_housetype" :disabled="disableSubmit" placeholder="请选择房屋性质"/>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="价值（万元）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['worth', validatorRules.worth]" :disabled="disableSubmit"
                              placeholder="请输入价值（万元）"
                              style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="年租金" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['rentYear', {}]" :disabled="disableSubmit"
                              placeholder="请输入年租金"
                              style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="空置原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['emptyReason', validatorRules.emptyReason]" :disabled="disableSubmit"
                       placeholder="请输入空置原因"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="具体问题" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['concreteIssue', validatorRules.concreteIssue]" :disabled="disableSubmit"
                       placeholder="请输入具体问题"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="是否有产权" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['isProperty']" :trigger-change="true"
                                 dictCode="yn" :disabled="disableSubmit" placeholder="请选择是否有产权"/>
            </a-form-item>
          </a-col>

<!--          <a-col :xs="24" :sm="12">-->
<!--            <a-form-item label="管区" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--&lt;!&ndash;              <a-input v-decorator="['regional', validatorRules.regional]" :disabled="disableSubmit"&ndash;&gt;-->
<!--&lt;!&ndash;                       placeholder="请输入管区"></a-input>&ndash;&gt;-->
<!--              <j-dict-select-tag type="list" v-decorator="['regional']"-->
<!--                                   :trigger-change="true" dictCode="zcgl_regional" :disabled="disableSubmit"-->
<!--                                   placeholder="请选择管区"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->

          <a-col :xs="24" :sm="12">
            <a-form-item label="原管理单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['originalManagementUnit', validatorRules.originalManagementUnit]"
                       :disabled="disableSubmit" placeholder="请输入原管理单位"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="原产权单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['originalPropertyRightUnit', validatorRules.originalPropertyRightUnit]"
                       :disabled="disableSubmit" placeholder="请输入原产权单位"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="批复文号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['approvalDocumentNumber', validatorRules.approvalDocumentNumber]"
                       :disabled="disableSubmit" placeholder="请输入批复文号"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="调拔时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date :disabled="disableSubmit" placeholder="请选择调拔时间" v-decorator="['pullTime']" :trigger-change="true"
                      style="width: 100%"/>
            </a-form-item>
          </a-col>

          <!--          <a-col :xs="24" :sm="12">-->
          <!--            <a-form-item label="上会时间" :labelCol="labelCol" :wrapperCol="wrapperCol">-->

          <!--              <a-input v-decorator="['meetingTime', validatorRules.meetingTime]"-->
          <!--                       :disabled="disableSubmit" placeholder="请输入上会时间"></a-input>-->
          <!--&lt;!&ndash;              <j-date :disabled="disableSubmit" placeholder="请选择上会时间" v-decorator="['meetingTime']"&ndash;&gt;-->
          <!--&lt;!&ndash;                      :trigger-change="true"&ndash;&gt;-->
          <!--&lt;!&ndash;                      style="width: 100%"/>&ndash;&gt;-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->

          <a-col :xs="24" :sm="12" v-show="isDisposal">
            <a-form-item label="资产处置" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['assetDisposal', validatorRules.assetDisposal]"
                                 :disabled="disableSubmit" :trigger-change="true" dictCode="asset_disposal" placeholder=""/>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12" v-show="isDisposal">
            <a-form-item label="处置日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date v-decorator="['assetDisposalDate', validatorRules.assetDisposalDate]"
                      :disabled="disableSubmit" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="所属公司" v-is-group :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-company-select-tag placeholder="请选择所属公司" :disabled="disableSubmit" v-decorator="[ 'companyId', validatorRules.companyId]" :trigger-change="true"/>
            </a-form-item>
          </a-col>

          <a-col :span="24" v-show="isDisposal">
            <a-form-item label="处置情况说明" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <a-textarea v-decorator="['assetDisposalDescription', validatorRules.assetDisposalDescription]"
                          :disabled="disableSubmit" rows="4" placeholder=""></a-textarea>
            </a-form-item>
          </a-col>

<!--          <a-col :span="24">-->
<!--            <a-form-item label="产权证地址" :labelCol="labelCol2" :wrapperCol="wrapperCol2">-->
<!--              <a-textarea v-decorator="['addressPropertyDivision', validatorRules.addressPropertyDivision]" rows="2"-->
<!--                          :disabled="disableSubmit" placeholder="请输入产权证地址"></a-textarea>-->
<!--            </a-form-item>-->
<!--          </a-col>-->


          <!--          <a href="http://apis.map.qq.com/tools/locpicker?search=1&type=0&backurl=https://baidu.com&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&referer=myapp">-->
          <!--            <input placeholder="请选择地址" readonly>-->
          <!--          </a>-->

          <a-col :span="24">
            <a-form-item label="坐落位置" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <a-textarea v-decorator="['site', validatorRules.site]" :disabled="disableSubmit" rows="2"
                          placeholder="请输入坐落位置"></a-textarea>
            </a-form-item>
          </a-col>

          <a-col :span="24">
            <a-form-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <a-textarea v-decorator="['remark', validatorRules.remark]" :disabled="disableSubmit" rows="2"
                          placeholder="请输入备注"></a-textarea>
            </a-form-item>
          </a-col>

          <a-col :span="24">
            <a-form-item label="资产图片" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <!--              class="avatar-uploader"-->
              <j-image-upload text="上传" v-model="images" :isMultiple="true" :disabled="disableSubmit" :number="6"></j-image-upload>
            </a-form-item>
          </a-col>

          <a-col :span="24" v-show="!disableSubmit">
            <a-form-item label="地图选点" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <iframe id="mapPage" width="100%" height="400px" frameborder=0
                      :src="tencentMapUrl">
              </iframe>
              <!--              <a-textarea v-decorator="['site', validatorRules.site]" :disabled="disableSubmit" rows="2"-->
              <!--                          placeholder="请输入坐落位置"></a-textarea>-->
            </a-form-item>
          </a-col>


          <a-col :span="24" v-show="disableSubmit">
            <a-form-item label="地图位置" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <div :id="container" style="height:400px;"></div>
            </a-form-item>
          </a-col>

          <a-col :xs="24" :sm="12">
            <a-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['accessory']" :disabled="disableSubmit" :trigger-change="true"></j-upload>
            </a-form-item>
          </a-col>

        </a-row>
      </a-form>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="资产明细" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="assetInfoSubTable.loading"
            :columns="assetInfoSubTable.columns"
            :dataSource="assetInfoSubTable.dataSource"
            :maxHeight="300"
            :disabled="disableSubmit"
            :rowNumber="true"
            :rowSelection="!disableSubmit"
            :actionButton="!disableSubmit"/>
        </a-tab-pane>
        <!--        :disabledRows="{ roomStatus: 20 }"-->

      </a-tabs>

    </a-spin>
</template>

<script>

import pick from 'lodash.pick'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import JDate from '@/components/jeecg/JDate'
import JUpload from '@/components/jeecg/JUpload'
import JImageUpload from '@/components/jeecg/JImageUpload'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JTreeSelect from '@/components/jeecg/JTreeSelect'
import { queryAssetImageByMainId } from '@/api/asset'
import maps from 'qqmap'
import { IS_GROUP } from '@/store/mutation-types'
import JCompanySelectTag from '@comp/jeecg/JCompanySelectTag'
import JSelectAssetCategory from '../../../components/jeecgbiz/JSelectAssetCategory'


export default {
  name: 'AssetInfo',
  mixins: [JEditableTableMixin],
  components: {
    JDate,
    JUpload,
    JImageUpload,
    JSearchSelectTag,
    JTreeSelect,
    JCompanySelectTag,
    JDictSelectTag,
    JSelectAssetCategory
  },
  data () {
    return {
      // form: this.$form.createForm(this),
      //腾讯地图
      tencentMapUrl: '',
      images: '',
      container: Math.random().toString(36).substr(2),
      latlng: {
        lng: 106.600782,
        lat: 29.718219
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 0,
      disableSubmit: false,
      isDisposal: false,
      validatorRules: {
        assetClass: {
          rules: [
            { required: true, message: '请输入取得方式!' }
          ]
        },
        assetCode: {
          rules: [
            { required: false, message: '请输入资产编码!' }
          ]
        },
        assetName: {
          rules: [
            { required: true, message: '请输入资产名称!' }
          ]
        },
        propertyRightUnit: {
          rules: [
            { required: true, message: '请输入产权单位!' }
          ]
        },
        // regionId: {
        //   rules: [
        //     { required: true, message: '请选择所属区域!' }
        //   ]
        // },
        // propertyRightCode: {
        //   rules: [
        //     { required: false, message: '请输入产权证编号!' }
        //   ]
        // },
        status: {
          rules: [
            { required: true, message: '请输入状态!' }
          ]
        },
        assetDisposal: {
          rules: [
            { required: false, message: '请选择处置类别!' }
          ]
        },
        floorNumber: {
          rules: [
            { required: false, message: '请输入楼层!' }
          ]
        },
        buildTime: {
          rules: [
            { required: false, message: '请输入建成年份!' }
          ]
        },
        houseStructure: {
          rules: [
            { required: false, message: '请输入结构!' }
          ]
        },
        houseUse: {
          rules: [
            { required: false, message: '请输入房屋用途!' }
          ]
        },
        site: {
          rules: [
            { required: true, message: '请输入坐落位置!' }
          ]
        },
        remark: {
          rules: [
            { required: false, message: '请输入备注!' }
          ]
        },
        propertyRightArea: {
          rules: [
            { required: false, message: '请输入产权面积（m²）!' }
          ]
        },
        coveredArea: {
          rules: [
            { required: false, message: '请输入建筑面积（m²）!' }
          ]
        },
        landUseArea: {
          rules: [
            { required: false, message: '请输入出租面积（m²）!' }
          ]
        },
        // businessCircumstance: {
        //   rules: [
        //     { required: false, message: '请输入经营情况!' }
        //   ]
        // },
        // receiptType: {
        //   rules: [
        //     { required: false, message: '请输入接收类型!' }
        //   ]
        // },
        managementUnitId: {
          rules: [
            { required: false, message: '请输入管理单位!' }
          ]
        },
        receiptTime: {
          rules: [
            { required: false, message: '请选择接收时间!' }
          ]
        },
        // landAuthorityType: {
        //   rules: [
        //     { required: false, message: '请选择权利类型!' }
        //   ]
        // },
        rightCitizenshipSituation: {
          rules: [
            { required: false, message: '请选择权籍情况!' }
          ]
        },
        // ownershipSituation: {
        //   rules: [
        //     { required: false, message: '请选择权属情况!' }
        //   ]
        // },
        holderRightName: {
          rules: [
            { required: false, message: '请选输入使用权人名称!' }
          ]
        },
        // licenseNumber: {
        //   rules: [
        //     { required: false, message: '请选输入使用权证号!' }
        //   ]
        // },
        collectionRate: {
          rules: [
            { required: false, message: '请选输入收款税率!' }
          ]
        },
        izMortgage: {
          rules: [
            { required: false, message: '请选择是否抵押!' }
          ]
        }
      },
      refKeys: ['assetInfoSub'],
      tableKeys: ['assetInfoSub'],
      activeKey: 'assetInfoSub',
      // 资产明细
      assetInfoSubTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '门牌号',
            key: 'roomName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '面积（m²）',
            key: 'roomArea',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '状态',
            key: 'roomStatus',
            type: FormTypes.select,
            // disabled: true,
            dictCode: 'zcgl_asset_status',
            width: '200px',
            placeholder: '请选择${title}',
            valueExclude: [1,20,80],
            // valueText: [10,30,40,50,60,70],
            defaultValue: '10',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          // {
          //   title: '上会时间',
          //   key: 'meetingTime',
          //   type: FormTypes.input,
          //   width: '200px',
          //   placeholder: '请输入${title}'
          // },
          // {
          //   title: '价值（万元）',
          //   key: 'worth',
          //   type: FormTypes.inputNumber,
          //   width: '200px',
          //   placeholder: '请输入${title}'
          // },
          {
            title: '空置原因',
            key: 'emptyReason',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}'
          },
          {
            title: '具体问题',
            key: 'concreteIssue',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}'
          }
        ]
      },
      url: {
        add: '/zcgl/assetInfo/add',
        edit: '/zcgl/assetInfo/edit',
        checkModel: '/zcgl/assetInfo/checkModel',
        assetInfoSub: {
          list: '/zcgl/assetInfo/queryAssetInfoSubByMainId'
        }
      }
    }
  },
  watch: {
    showModal: function (newValue) {
      if (newValue) {
        this.init()
      }
    }
  },
  mounted () {
    let that = this
    window.addEventListener('message', function (event) {
      // 对于无法识别的地址，直接返回无法选择
      let loc = event.data
      // if (loc.poiname === '我的位置' || loc.poiaddress === '') {
      //   console.log('无法识别该地址，请移动地图重新选择')
      //   return false
      // }
      if (loc && loc.module === 'locationPicker') { // 防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
        console.log('callback', loc)
        that.latlng = loc.latlng

        // that.latlng.lat = loc.latlng.lat
        // that.latlng.lng = loc.latlng.lng
        // console.log(this.latlng)
        // this.setLatlng(loc)
      }
    }, false)
  },

  methods: {
    //初始化地图
    init () {
      var that = this
      maps.init(`${window._CONFIG['tencentMapKey']}`, () => {
        let myLatlng = new qq.maps.LatLng(that.latlng.lat, that.latlng.lng)
        let myOptions = {
          zoom: 16,
          center: myLatlng,
          mapTypeId: qq.maps.MapTypeId.ROADMAP
        }
        let map = new qq.maps.Map(
          document.getElementById(that.container),
          myOptions
        )
        let marker = new qq.maps.Marker({
          position: myLatlng,
          map: map
        })
      })
    },
    getAllTable () {
      let values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    showModal (r) {
      this.model = Object.assign({}, r)
      this.images = ''


      let isGroup = sessionStorage.getItem(IS_GROUP)
      if (isGroup == 1) {
        let companyName = {
          rules: [{
            required: true, message: '请选择所属公司!'
          }]
        }
        this.validatorRules.companyId = companyName
      }

      let tencentMapUrl1 = `${window._CONFIG['tencentMapUrl']}`
      if (this.model.latitude && this.model.longitude) {
        this.latlng.lat = this.model.latitude
        this.latlng.lng = this.model.longitude
        tencentMapUrl1 += `&coord=${this.model.latitude},${this.model.longitude}`
      }

      this.tencentMapUrl = tencentMapUrl1
      console.log("tencentMapUrl1:" + tencentMapUrl1)

      // this.$refs.assetInfo.images = ""
      if (this.model.status == 1) {
        this.model.status = this.model.initStatus
      }
      this.$nextTick(() => {
        let keys = Object.keys(this.form.formItems)
        this.form.setFieldsValue(pick(this.model, keys))
        this.statusChange(this.model.status)
        this.init()
        if (this.model.assetInfoSubList != undefined){
          this.assetInfoSubTable.dataSource = this.model.assetInfoSubList

          let imagesVo = this.model.assetImageList
          let fileList = []
          if (imagesVo && imagesVo.length > 0) {
            imagesVo.forEach((v, i) => {
              // if (that.disableSubmit){
              //   that.repairImageList.push(getFileAccessHttpUrl(v.imageUrl))
              // } else {
              fileList.push(v.imageUrl)
              // }
            })
          }
          this.images = fileList.join(',')
        } else {
          this.selectSub()
        }
        // this.form.setFieldsValue(fieldval)
      })
    },
    selectSub(){
      let params = { id: this.model.id }
      this.requestSubTableData(this.url.assetInfoSub.list, params, this.assetInfoSubTable)
      this.getImages()
    },
    statusChange(val){
      if (val == 40){
        this.isDisposal = true
        this.validatorRules.assetDisposal.rules[0].required = true
      } else {
        this.isDisposal = false
        this.validatorRules.assetDisposal.rules[0].required = false
      }
    },
    /** 整理成formData */
    classifyIntoFormData (allValues) {
      let that = this
      let main = Object.assign(this.model, allValues.formValue)
      main.latitude = this.latlng.lat
      main.longitude = this.latlng.lng

      let assetImageList = []
      if (this.images && this.images.split(',') != '') {
        this.images.split(',').forEach((v, i) => {
          assetImageList.push({
            imageUrl: v,
            type: 0,
            assetId: that.model.id
          })
        })
      }
      main.assetImageList = assetImageList
      return {
        ...main, // 展开
        assetInfoSubList: allValues.tablesValue[0].values
      }
    },
    validateError (msg) {
      this.$message.error(msg)
    },
    popupCallback (row) {
      let keys = Object.keys(this.form.formItems);
      this.form.setFieldsValue(pick(row, keys))
    },
    getImages () {
      let that = this
      queryAssetImageByMainId({ id: this.model.id }).then((res) => {
        if (res.success) {
          if (res.result && res.result.length > 0) {
            let fileList = []
            res.result.forEach((v, i) => {
              // if (that.disableSubmit){
              //   that.repairImageList.push(getFileAccessHttpUrl(v.imageUrl))
              // } else {
              fileList.push(v.imageUrl)
              // }
            })
            that.images = fileList.join(',')
          }
        } else {
          that.images = ''
        }
      }).finally(() => {
        // that.$previewRefresh()
      })
    },

  }
}
</script>

<style scoped>
</style>